import Taro, { Component } from '@tarojs/taro'
import { connect } from '@tarojs/redux'
import PropTypes from 'prop-types'
import _isEmpty from 'lodash/isEmpty'
import { View, Text } from '@tarojs/components'
import { printOrderContent } from '@/actions/order'

import BaseButton from '@/components/BaseButton'
import RowTip from '@/components/RowTip'
import AddressLine from '@/components/AddressLine'

import { checkOrderOver20 } from '../../utils'

import './index.scss'

@connect(({order}) => ({
	order
}))
class OrderItem extends Component {

	static propTypes = {
		data: PropTypes.object,						
		onClick: PropTypes.func,
	}

	static defaultProps = {
		data: {}
	}

	constructor(props){
		super(props)
		this.state = {

		}
	}

	render(){
		const { data } = this.props

		const againOrder = data && (data.orderStatusCode === 'publish_cancel' || data.orderStatusCode === 'taking_cancel' || data.orderStatusCode === 'overtime_close' || data.orderStatusCode === 'system_close'|| data.orderStatusCode === 'goods_stop')
		// const timeOver = checkOrderOver20(data)
		const traData = !_isEmpty(data) ?  {
			type: data.trafficTypeCode,           
			typeCn: data.trafficTypeCn,
			lineStart: data.carrierLineStart,
			lineEnd: data.carrierLineEnd,
			sender: data.senderName,         
			receiver: data.receiverName    
		} : {}
		return (
			<View className='mine-order-item' onClick={() => this.handleItemClick('detail')}>
				{/* <View className='item-conten-text'>航班号：南航MU2345</View> */}
				<View className='mine-order-item-line'>
					<AddressLine data={traData} isMore traType={data.trafficTypeCode}/>
				</View>
				<View className='mine-order-item-content'>
					<View className='item-content-left'>
						{/* <View className='item-content-left-text'>最晚取消时间：4月8日16：00</View> */}
						{/* <RowTip text='注：超过此时间取消，影响发车会发生取消订舱费' /> */}
						{/* <View className='item-content-left-text'>交货时间:4月8日 11：30</View>
						<View className='item-content-left-text'>交货地点:萧山区萧绍路383号</View> */}
						<View className='item-conten-text'>订单编号：{data.orderNumber}</View>
						{data.trackingNumber && <View className='item-conten-text'>运单编号：{data.trackingNumber}</View>}
						
					</View>
					<View className='item-content-state'>{data.orderStatusCn}</View>
				</View>
				{/* <View className='item-content-warn'>问题件处理倒计时：<Text>0分钟 </Text>专属运营正在处理中</View> */}
				<View className='mine-order-item-btns'>
					{(data.orderStatusCode === 'taking' || data.orderStatusCode === 'trafficing' || data.orderStatusCode === 'finish' || data.orderStatusCode === 'evaluate') && <BaseButton cls='item-btn' text='打印订单' center={false}  width={100} height={36} onClick={(e) => this.handleItemClick('print')}/>}
				</View>
			</View>
		)
	}

	handleItemClick = (type) => {
		console.log('点击===', type)
		const { data } = this.props
		switch (type) {
			case 'detail':
				console.log('查看物流')
				Taro.navigateTo({ url: `/pages/detail/index?type=${data.trafficTypeCode}&rId=${data.id}`})
				break;
			case 'print': 
				console.log('打印订单==')
				break;
			case 'evaluate':
				console.log('评价')
				break;
			default:
				break;
		}
	}

	toOrderDetail = (rId) => {
		Taro.navigateTo({ url: `/pages/detail/index?rId=${rId}`})
	}
}

export default OrderItem